package kr.hkit.androidcomplete03.ch20;

import kr.hkit.androidcomplete03.R;
import kr.hkit.androidcomplete03.ch20.FragmentTest.CounterFragment;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;

public class FragmentBackStack extends Activity {
	int mStart = 10;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragmentargument);
		
		if (savedInstanceState!=null){
			mStart = savedInstanceState.getInt("mStart");
		}
		
		CounterFragment cf = new CounterFragment();
		Bundle args = new Bundle();
		args.putInt("start", mStart);
		cf.setArguments(args);
		
		getFragmentManager().beginTransaction()
		.add(R.id.fragmentargument_frame, cf, "counter").commit();
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putInt("mStart", mStart);
	}
	
	public void mOnClick(View v){
		if (v.getId() == R.id.fragmentargument_btnadd){
			mStart+=10;
			CounterFragment cf = new CounterFragment();
			Bundle args = new Bundle();
			args.putInt("start", mStart);
			cf.setArguments(args);
			
			getFragmentManager().beginTransaction()
			.replace(R.id.fragmentargument_frame, cf, "counter")
			.addToBackStack(null)
			.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
			.commit();

		}
	}
}
